#!/bin/bash
set -e


while getopts  ":b:p:" opts
do
	case  $opts  in
	p)
		out_prefix=$OPTARG
		;;
	b)
	assembly=$OPTARG
	;;
	\?)
		echo `basename $0` ' [-b assembly] [-p out_prefix] <input.bam> <interval.bed>'
		exit 1
		;;
	esac
done
shift $(($OPTIND - 1))


if [ -z "$2" ]; then
	echo `basename $0` ' [-b assembly] [-p out_prefix] <input.bam> <interval.bed>'
	exit 1
fi

#-----------------------------------------------
. /mnt/ilustre/app/medical/tools/.var #---------
#-----------------------------------------------


if [ -z $out_prefix ]; then
	out_prefix=1.gatk.depth
fi



echo genome assembly is: $genome_assembly 2>>$log 1>&2
echo ref genome is: $ref_genome 2>>$log 1>&2


# For gatk, Each read group must contain the platform (PL) and sample (SM) tags.
# For the platform value, we currently support 454, LS454, Illumina, Solid, ABI_Solid, and CG (all case-insensitive).
# Each read in the file must be associated with exactly one read group.

# vcf_path=${data_path}/vcf/gatk/

# there is no space between "=" and "\"
# ref_genome=\
# ${data_path}/ref/b37/$genome_name







# echo 2>>$log 1>&2
# echo gatk summary 2>>$log 1>&2
# java -Xmx$java_memory -jar $gatk \
   # -T DepthOfCoverage \
   # -R $ref_genome \
   # -o 1.tes \
   # -I $1 \
   # -ct 1 -ct 10 -ct 30 -ct 100 \
   # -L $interval_brca12 \
   # 2>>$log
   
echo;echo;echo gatk summary
java -Xmx$java_memory -jar $gatk \
   -T DepthOfCoverage \
   -R $ref_genome \
   -I $1 \
   -o $out_prefix \
   --omitDepthOutputAtEachBase \
   --omitLocusTable \
   --outputFormat csv \
   --minBaseQuality 20 \
   --minMappingQuality 20 \
   -L $2 \
   -ct 1
   
# echo 2>>$log 1>&2
# echo gatk summary 2>>$log 1>&2
# java -Xmx$java_memory -jar $gatk \
   # -T DepthOfCoverage \
   # -R $ref_genome \
   # -o 1.tes \
   # -I $1 \
   # -ct 1 \
   # -L $interval_brca12 \
   # 2>>$log
   
# [-geneList refSeq.sorted.txt] \
# [-pt readgroup] \